package com.itheima.patterns.builderpattern.factorymethod.iteratordemo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IteratorDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("Tom");
        list.add("Mike");
        list.add("Marry");
    
        //获取迭代器对象
        Iterator<String> iterator = list.iterator();
        //使用迭代器遍历
        while(iterator.hasNext()){
            String element = iterator.next();
            System.out.println(element);
        }
    }
}